Inside Macintosh: QuickTime Components

Previous | Chapter Top | Chapter Contents | Next

Application-Defined Functions

This section describes the functions that your application may supply to sequence grabber components.

Your grab function is used by the sequence grabber component to begin the capture of a frame of video data. Your grab-complete function allows the sequence grabber component to determine whether the current frame-capture operation is complete.

Your display function enables the sequence grabber component to move a captured video image in an offscreen buffer into the destination buffer for the video channel.

The sequence grabber component uses your compress function to commence the compression of a captured video image. Your compress-complete function helps the sequence grabber component to find out if the current frame-compression operation is finished.

Your add-frame function lets the sequence grabber component add a frame to a movie.

The sequence grabber component uses your transfer-frame function to move a video frame from the capture buffer into the channel's filter buffer.

You may provide two functions for use with compressed-source devices. Your grab-compress-complete function determines when the current capture and compress operation is complete. Your display-compress function decompresses and displays a frame.

The sequence grabber calls your data function whenever any of the grabber's channels write data to the movie file.

If you call the SGSettingsDialog function, described on SGSettingsDialog , you must supply a modal-dialog filter function. The interface that your function must provide is discussed on MyModalFilter .

MyGrabFunction

The sequence grabber component calls your grab function in order to start capturing a frame of video data.

Your grab function must present the following interface:

pascal ComponentResult MyGrabFunction (SGChannel c,
                                         short bufferNum,
                                         long refCon);
c
Specifies the reference that identifies the channel for this operation.
bufferNum
Identifies the buffer for this operation. You can obtain information about this buffer by calling the SGGetBufferInfo function, which is described on SGGetBufferInfo .
refCon
Contains a reference constant value. You can set this value by calling the SGSetChannelRefCon function, which is described on SGSetChannelRefCon .

RESULT CODE

cantDoThatInCurrentMode

-9402

Request invalid in current mode

SEE ALSO

Your grab function can use the sequence grabber component's SGGrabFrame function to support the default behavior. SGGrabFrame is described on SGGrabFrame .

MyGrabCompleteFunction

The sequence grabber component calls your grab-complete function in order to determine whether the current frame-capture operation is complete. Once a frame has been completely captured, you can modify its contents to suit your needs. For example, you can overlay text onto the video image.

Your function must present the following interface:

pascal ComponentResult MyGrabCompleteFunction (SGChannel c,
                                          short bufferNum,
                                         Boolean *done,
                                          long refCon);
c
Specifies the reference that identifies the channel for this operation.
bufferNum
Identifies the buffer for this operation. You can obtain information about this buffer by calling the SGGetBufferInfo function, which is described on SGGetBufferInfo .
done
Contains a pointer to a Boolean value. Your function sets this Boolean value to indicate whether the frame has been completely captured. Set the Boolean value to true if the capture is complete; set it to false if it is incomplete.
refCon
Contains a reference constant value. You can set this value by calling the SGSetChannelRefCon function, which is described on SGSetChannelRefCon .

RESULT CODE

cantDoThatInCurrentMode

-9402

Request invalid in current mode

SEE ALSO

Your grab-complete function can use the sequence grabber component's SGGrabFrameComplete function to support the default behavior. SGGrabFrameComplete is described on SGGrabFrameComplete .

See Listing 6 for a sample grab-complete function. This function draws the letters "QT" over each video frame in the sequence.

MyDisplayFunction

The sequence grabber component calls your display function in order to transfer a captured video image in an offscreen buffer into the destination buffer for the video channel.

Your display function must support the following interface:

pascal ComponentResult MyDisplayFunction (SGChannel c,
                                          short bufferNum,
                                          MatrixRecord *mp,
                                          RgnHandle clipRgn,
                                          long refCon);
c
Specifies the reference that identifies the channel for this operation.
bufferNum
Identifies the buffer for this operation. You can obtain information about this buffer by calling the SGGetBufferInfo function, which is described on SGGetBufferInfo .
mp
Contains a pointer to a transformation matrix for the display operation. If there is no matrix for the operation, this parameter is set to nil .
clipRgn
Contains a handle to the clipping region for the destination image. This region is defined in the destination coordinate system. Apply the clipping region after applying the transformation matrix. If there is no clipping region, this parameter is set to nil .
refCon
Contains a reference constant value. You can set this value by calling the SGSetChannelRefCon function, which is described on SGSetChannelRefCon .

RESULT CODE

cantDoThatInCurrentMode

-9402

Request invalid in current mode

SEE ALSO

Your application sets the destination buffer by calling the SGSetChannelBounds function, which is described on SGSetChannelBounds .

Your display function can use the sequence grabber component's SGDisplayFrame function to support the default behavior. SGDisplayFrame is described on SGDisplayFrame .

MyCompressFunction

The sequence grabber component calls your compress function in order to start compressing the captured video image.

Your compress function must support the following interface:

pascal ComponentResult MyCompressFunction (SGChannel c,
                                          short bufferNum,
                                          long refCon);
c
Specifies the reference that identifies the channel for this operation.
bufferNum
Identifies the buffer for this operation. You can obtain information about this buffer by calling the SGGetBufferInfo function, which is described on SGGetBufferInfo .
refCon
Contains a reference constant value. You can set this value by calling the SGSetChannelRefCon function, which is described on SGSetChannelRefCon .

RESULT CODES

cantDoThatInCurrentMode

-9402

Request invalid in current mode

Image Compression Manager errors

SEE ALSO

Your compress function can use the sequence grabber component's SGCompressFrame function to support the default behavior. SGCompressFrame is described on SGCompressFrame . This function uses the Image Compression Manager to compress the video image. For more on the Image Compression Manager, see Inside Macintosh: QuickTime .

MyCompressCompleteFunction

The sequence grabber component calls your compress-complete function in order to determine whether the current frame-compression operation is complete.

Your compress-complete function must support the following interface:

pascal ComponentResult MyCompressCompleteFunction (SGChannel c,
                                          short bufferNum,
                                         Boolean *done,
                                          SGCompressInfo *ci,
                                         long refCon);
c
Specifies the reference that identifies the channel for this operation.
bufferNum
Identifies the buffer for this operation. You can obtain information about this buffer by calling the SGGetBufferInfo function, which is described on SGGetBufferInfo .
done
Contains a pointer to a Boolean value. Your function sets this Boolean value to indicate whether the frame has been completely compressed. Set the Boolean value to true if the compression is complete; set it to false if it is incomplete.
ci
Contains a pointer to a compression information structure (defined by the SGCompressInfo data type). If the compression is complete, your function must completely format this structure with information that is appropriate to the frame just compressed. See "The Compression Information Structure," , for a description of this structure.
refCon
Contains a reference constant value. You can set this value by calling the SGSetChannelRefCon function, which is described on SGSetChannelRefCon .

DESCRIPTION

Once a frame has been completely compressed, you can add it to the movie.

SEE ALSO

Your compress-complete function can use the sequence grabber component's SGCompressFrameComplete function to support the default behavior. SGCompressFrameComplete is described on SGCompressFrameComplete .

RESULT CODES

cantDoThatInCurrentMode

-9402

Request invalid in current mode

Image Compression Manager errors

MyAddFrameFunction

The sequence grabber component calls your add-frame function in order to add a frame to a movie. Your add-frame function must support the following interface:

pascal ComponentResult MyAddFrameFunction (SGChannel c,
                                         short bufferNum,
                                         TimeValue atTime,
                                         TimeScale scale,
                                         SGCompressInfo *ci,
                                         long refCon);
c
Specifies the reference that identifies the channel for this operation.
bufferNum
Identifies the buffer for this operation. You can obtain information about this buffer by calling the SGGetBufferInfo function, which is described on SGGetBufferInfo .
atTime
Specifies the time at which the frame was captured, in the time scale specified by the scale parameter. Your add-frame function can change this value before adding the frame to the movie or before calling the SGAddFrame function, which is described on SGAddFrame . You can determine the duration of a frame by subtracting its capture time from the capture time of the next frame in the sequence.
scale
Specifies the time scale of the movie. You must not change this value.
ci
Contains a pointer to a compression information structure (defined by the SGCompressInfo data type). This structure contains information describing the compression characteristics of the image to be added to the movie. See "The Compression Information Structure," for a description of this structure.
refCon
Contains a reference constant value. You can set this value by calling the SGSetChannelRefCon function, which is described on SGSetChannelRefCon .

DESCRIPTION

You can use your add-frame function to modify the contents of the frame before it is added to the movie. This can be useful if you want to place frame numbers onto frames you are recording.

RESULT CODES

cantDoThatInCurrentMode

-9402

Request invalid in current mode

Memory Manager errors

SEE ALSO

Your add-frame function can use the sequence grabber component's SGAddFrame function to support the default behavior. SGAddFrame is described on SGAddFrame .

MyTransferFrameFunction

The sequence grabber component calls your transfer-frame function in order to move a video frame from the capture buffer into the channel's filter buffer.

Your transfer-frame function must support the following interface:

pascal ComponentResult MyTransferFrameFunction (SGChannel c,
                                         short bufferNum,
                                         MatrixRecord *mp,
                                         RgnHandle clipRgn,
                                         long refCon);
c
Specifies the reference that identifies the channel for this operation.
bufferNum
Identifies the buffer for this operation. You can obtain information about this buffer by calling the SGGetBufferInfo function, which is described on SGGetBufferInfo .
mp
Contains a pointer to a transformation matrix for the transfer operation. If there is no matrix for the operation, this parameter is set to nil .
clipRgn
Contains a handle to the clipping region for the destination image. This region is defined in the destination coordinate system. Apply the clipping region after applying the transformation matrix. If there is no clipping region, this parameter is set to nil .
refCon
Contains a reference constant value. You can set this value by calling the SGSetChannelRefCon function, which is described on SGSetChannelRefCon .

DESCRIPTION

The sequence grabber component calls this function only when you are filtering the video data. By filtering the video data through a filter buffer, you can eliminate some visual artifacts that result from noisy input video sources. Your application sets a filter buffer by calling the SGSetCompressBuffer function, which is described on SGSetCompressBuffer .

If you are using a grab-complete function to determine when frames have been grabbed, you should also implement a grab-compress-complete function (described in the next section). Otherwise, the channel will decompress the specified image before calling your grab-complete function, which will result in significantly lower performance. For details on grab-complete functions, see MyGrabCompleteFunction .

RESULT CODE

cantDoThatInCurrentMode

-9402

Request invalid in current mode

SEE ALSO

Your transfer-frame function can use the sequence grabber component's SGTransferFrameForCompress function to support the default behavior-- SGTransferFrameForCompress is described on SGTransferFrameForCompress .

MyGrabCompressCompleteFunction

The sequence grabber calls your grab-compress-complete function when it is working with a video digitizer that supports compressed source data. Your grab-compress-complete function is responsible for determining whether the current compressed frame has been completely captured and compressed, essentially combining your grab-complete, compress, and compress-complete functions into one function.

Your function must support the following interface:

pascal ComponentResult MyGrabCompressCompleteFunction
                                         (SGChannel c,
                                          Boolean *done,
                                          SGCompressInfo *ci,
                                          TimeRecord *tr,
                                          long refCon);
c
Identifies the channel for this operation.
done
Contains a pointer to a Boolean value. Set this Boolean value to indicate whether you are finished. Set it to true when you are done; set it to false if the operation is incomplete.
ci
Contains a pointer to a compression information structure. When the operation is complete, fill in this structure with information about the compression operation. The format and content of this structure are discussed earlier in this chapter, beginning on The Compression Information Structure .
tr
Contains a pointer to a time record. When the operation is complete, fill in this structure with information indicating when the frame was grabbed. The format and content of this structure are discussed in the chapter "Movie Toolbox" in Inside Macintosh: QuickTime .
refCon
Contains a reference constant value. You can set this value by calling the SGSetChannelRefCon function, which is described on SGSetChannelRefCon .

RESULT CODE

cantDoThatInCurrentMode

-9402

Request invalid in current mode

SEE ALSO

Your grab-compress-complete function may use the sequence grabber's SGGrabCompressComplete function to support the default behavior. SGGrabCompressComplete is discussed beginning on SGGrabCompressComplete .

MyDisplayCompressFunction

The sequence grabber calls your display-compress function when it is working with a video digitizer component that supports compressed source data. Your display-compress function is responsible for decompressing and displaying a compressed image.

pascal ComponentResult MyDisplayCompressFunction (SGChannel c,
                                         Ptr dataPtr,
                                         ImageDescriptionHandle desc,
                                         MatrixRecord *mp,
                                         RgnHandle clipRgn,
                                         long refCon);
c
Identifies the channel for this operation. The sequence grabber provides this value to your display-compress function.
dataPtr
Contains a pointer to the compressed image data.
desc
Specifies a handle to the image description structure to use for the decompression operation. See the chapter "Image Compression Manager" in Inside Macintosh: QuickTime for more information about this data structure.
mp
Contains a pointer to a matrix structure. This matrix structure contains the transformation matrix to use when displaying the image. If there is no matrix for the operation, this parameter is set to nil .
clipRgn
Contains a handle to the clipping region for the destination image. This region is defined in the destination coordinate system. Apply the clipping region after the transformation matrix. If there is no clipping region, this parameter is set to nil .
refCon
Contains a reference constant value. You can set this value by calling the SGSetChannelRefCon function, which is described on SGSetChannelRefCon .

RESULT CODE

cantDoThatInCurrentMode

-9402

Request invalid in current mode

SEE ALSO

Your display-compress function may use the sequence grabber's SGDisplayCompress function to support the default behavior. SGDisplayCompress is discussed beginning on SGDisplayCompress .

MyDataFunction

The sequence grabber calls your data function whenever any of the grabber's channels write digitized data to the destination movie file. You assign a data function to the sequence grabber by calling the SGSetDataProc function, which is discussed on SGSetDataProc .

Your data function must support the following interface:

pascal OSErr MyDataFunction (SGChannel c, Ptr p, long len,
                                         long *offset, long chRefCon,
                                         TimeValue time, short writeType,
                                         long refCon);
c
Identifies the channel component that is writing the digitized data.
p
Contains a pointer to the digitized data.
len
Indicates the number of bytes of digitized data.
offset
Contains a pointer to a field that may specify where you are to write the digitized data, and that is to receive a value indicating where you wrote the data. You must update the field referred to by this parameter, supplying the value indicated by the writeType parameter.
chRefCon
Contains control information. The low-order 16 bits contain sample flags for use by the Movie Toolbox's AddMediaSample function (see the chapter "Movie Toolbox" in Inside Macintosh: QuickTime for information about these flags). The sequence grabber sets these flags as appropriate.
The high-order 16 bits are reserved for Apple and are always set to 0.
time
Identifies the starting time of the data, in the channel's time scale. You may use the SGGetChannelTimeScale function to retrieve the channel's time scale (discussed on SGGetChannelTimeScale ).
writeType
Indicates the type of write operation being performed. The following values are defined:
seqGrabWriteAppend
Append the new data to the end of the file. Set the field referred to by the offset parameter to reflect the location at which you added the data.
seqGrabWriteReserve
Do not write any data to the output file. Instead, reserve space in the output file for the amount of data indicated by the len parameter. Set the field referred to by the offset parameter to the location of the reserved space.
seqGrabWriteFill
Write the data into the location specified by the field referred to by the offset parameter. Set that field to the location of the byte following the last byte you wrote.
This option is used to fill the space reserved previously when the writeType parameter was set to seqGrabWriteReserve . Note that the sequence grabber may call your data function several times to fill a single reserved location.
refCon
Contains the reference constant you specified when you assigned your data function to the sequence grabber.

DESCRIPTION

The sequence grabber calls your data function whenever any channel component writes data to the destination movie. You may use your data function to store the digitized data in some format other than a QuickTime movie.

RESULT CODES

File Manager errors Memory Manager errors

SEE ALSO

You can instruct the sequence grabber not to write its data to a QuickTime movie by calling the SGSetDataOutput function and setting the seqGrabDontMakeMovie flag to 1. This can save processing time in cases where you do not want to create or update a movie. SGSetDataOutput is discussed on SGSetDataOutput .

MyModalFilter

The SGSettingsDialog function causes the sequence grabber to present its settings dialog box to the user. This is a movable modal dialog box, so you must provide a filter function to handle update events in your window. You specify your filter function with the proc parameter.

A modal-dialog filter function whose address is passed to SGSettingsDialog should support the following interface:

pascal Boolean MyModalFilter (DialogPtr theDialog,
                                         EventRecord *theEvent,
                                         short *itemHit, long refCon);
theDialog
Points to the settings dialog box's dialog structure.
theEvent
Contains a pointer to an event structure. This event structure contains information identifying the nature of the event.
itemHit
Contains a pointer to a field that contains the item selected by the user. If you handle the event, you should update this field to reflect the item number of the selected item.
refCon
Contains a reference constant. You provide this reference constant to the sequence grabber in the procRefNum parameter of the SGSettingsDialog function, which is described on SGSettingsDialog .

DESCRIPTION

Your modal-dialog filter function returns a Boolean value that indicates whether you handled the event. Set this value to true if you handled the event; otherwise, set it to false . If you handle the event, be sure to update the value of the field referred to by the itemHit parameter.

SEE ALSO

See Inside Macintosh: Files for a sample modal-dialog filter function.


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next